//
//  THJQihuoSelecteView.m
//  THJXHW
//
//  Created by 河南德艺 on 2017/6/27.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJQihuoSelecteView.h"
#import "ZBNetworking.h"

@interface THJQihuoSelecteView()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * _tableview;
    NSString * qihuotype;
    NSArray * dataArr;
}
@property (nonatomic,strong)NSArray * titleListArr;
@end
@implementation THJQihuoSelecteView
-(instancetype)initWithArr:(NSArray *)arr{
    if (self = [super init]) {
        dataArr = arr;
        [self setUI];
    }
    return self;
}

-(void)setUI{
    NSLog(@"&&-**-%@",dataArr);
    CGFloat height = dataArr.count * 44;
    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0,0,ScreenWidth,30)];
    bgView.backgroundColor = SingleColor(whiteColor);
    [self addSubview:bgView];
    
    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, ScreenWidth, height) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self addSubview:_tableview];
    
    
    UIView * btnView = [[UIView alloc] initWithFrame:CGRectMake(0,height + 30,ScreenWidth,50)];
    btnView.backgroundColor = SingleColor(whiteColor);
    [self addSubview:btnView];
    
    UIButton * cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    cancelBtn.frame = CGRectMake(15, 5, ScreenWidth - 30, 40);
    cancelBtn.layer.masksToBounds = YES;
    cancelBtn.layer.cornerRadius = 5;
    cancelBtn.backgroundColor = SingleColor(orangeColor);
    [cancelBtn setTintColor:SingleColor(whiteColor)];
    [cancelBtn addTarget:self action:@selector(cancelSelect) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:cancelBtn];
}
-(void)cancelSelect{
    [self removeFromSuperview];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic = dataArr[indexPath.row];
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = dic[@"name"];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   NSDictionary * dic = dataArr[indexPath.row];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.delegate selectedType:qihuotype infoDic:dic];
    NSLog(@"%@,%@",qihuotype,dic);
    [self removeFromSuperview];
}
@end
